package blackjack.server;

import java.io.*;
import java.net.*;

public class Server {

	private static final int PORT = 8888;

	public static void main(String[] args) throws IOException {
		ActiveSessions  activeSessions  = new ActiveSessions ();
		OutboundMessages outQueue  = new OutboundMessages();
		ServerSocket serv = new ServerSocket(PORT);
		System.out.println("Server started...");
		new Broadcaster(activeSessions , outQueue );

		try {
			while (true) { // while server is running
				Socket sock = serv.accept(); 
				try {
					if(activeSessions.kokku != 0)continue;
					new ClientSession(sock, outQueue , activeSessions );//clientSession.start

				} catch (IOException e) {
					System.out.println("Socket error");
					sock.close();
				}
			} 
		} finally {
			System.out.println("Server closed");
			serv.close();
		}
	}

}